package com.ruoyi.system.mapper;

import com.ruoyi.system.domain.SysAnnounManagement;
import com.ruoyi.system.domain.SyseEventsPosted;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 大赛公告管理 数据层
 *
 * @author ganshiyu
 */
public interface SysAnnounManagementMapper {

     /**
      *  大赛公告管理  条件查询+分页
      *  后台管理中的大事管理和校园工作台共同使用接口
      *  当schoolName不为空时是校园工作台在使用接口
      *  当schoolname为空是是后台管理在使用接口
      * @param sysAnnounManagement 实体类
      * @return 对象列表
      */
     @Select("<script> "+
          "select amid,amTitle,amIntroduction,amReleaseTime,(case " +
          " when amState='0' then '未发布' "+
          "        when amState='1' then'已发布'" +
          "        when amState='2' then'已结束' " +
          "   end)'amState' " +
          " from announcement_management where 1=1 " +
          " <if test='amTitle!=\"\" and amTitle!=null'>"+
          "and amTitle=#{amTitle}"+
          "</if>"+

          " <if test='amState!=\"\" and amState!=null'>"+
          "and amState in(case  when amState=#{amState} then #{amState} end)"+
          "</if>"+

          " <if test='amEplevel!=\"\" and amEplevel!=null'>"+
          "and amEplevel=#{amEplevel}"+
          "</if>"+

          " <if test='schoolName!=\"\" and schoolName!=null'>"+
          "and schoolName=#{schoolName}"+
          "</if>"+
             " order by amid desc " +
          "LIMIT #{currentPage},#{pageSize}"+
          "</script>")
     List<SysAnnounManagement> selectByPage(SysAnnounManagement sysAnnounManagement );

     /**
      * 查询赛事表总数据量
      * 后台管理中的大事管理和校园工作台共同使用接口
      * 当schoolName不为空时是校园工作台在使用接口
      * 当schoolname为空是是后台管理在使用接口
      * @param sysAnnounManagement 实体类
      * @return 结果
      */
     @Select("<script> " +
          "select count(1) from announcement_management  where 1=1"+
          " <if test='amTitle!=\"\" and amTitle!=null'>"+
          "and amTitle=#{amTitle}"+
          "</if>"+

          " <if test='amState!=\"\" and amState!=null'>"+
          "and amState in(case  when amState=#{amState} then #{amState} end)"+
          "</if>"+

          " <if test='amEplevel!=\"\" and amEplevel!=null'>"+
          "and amEplevel=#{amEplevel}"+
          "</if>"+
          " <if test='schoolName!=\"\" and schoolName!=null'>"+
          "and schoolName=#{schoolName}"+
          "</if>"+
          "</script>")
     long selectCount(SysAnnounManagement sysAnnounManagement);

     /**
      * 大赛公告添加
      * 后台管理中的大事管理和校园工作台共同使用接口
      * 当schoolName不为空时是校园工作台在使用接口
      *当schoolname为空是是后台管理在使用接口
      * @param sysAnnounManagement 实体类
      * @return 结果
      */
     @Insert("<script>"+
          "insert into announcement_management(amTitle,amEplevel," +
          "amReleaseTime,amState,amIntroduction,amContentHeading" +
          " <if test='schoolName!=\"\" and schoolName!=null'>"+
          ",schoolName"+
          "</if>"+
          ",amDetails" +
          " <if test='amPic!=\"\" and amPic!=null'>"+
          ",amPic"+
          "</if>"+
          ")" +
          "values(#{amTitle},#{amEplevel},#{amReleaseTime},#{amState}," +
          "#{amIntroduction},#{amContentHeading}" +
          " <if test='schoolName!=\"\" and schoolName!=null'>"+
          ",#{schoolName}"+
          "</if>"+
          ",#{amDetails}" +
          " <if test='amPic!=\"\" and amPic!=null'>"+
          ",#{amPic}"+
          "</if>"+
          ")"+
          "</script>"
     )
     int insertAnnounManagement(SysAnnounManagement sysAnnounManagement);

     /**
      *  修改大赛公告管理状态
      *后台管理中的大事管理和校园工作台共同使用接口
      * @param amid
      * @return 结果
      */
     @Update("update announcement_management set amState='1' where amid=#{amid}")
     int editState(int amid);

     /**
      *  通过id查询对象
      * 后台管理中的大事管理和校园工作台共同使用接口
      * @param amid
      * @return 对象
      */
     @Select("select * from announcement_management where amid=#{amid}")
     SysAnnounManagement selectById(int amid);

     /**
      * 修改大赛公告
      * 后台管理中的大事管理和校园工作台共同使用接口
      * @param sysAnnounManagement 实体类
      * @return 结果
      */
     @Update(
          "<script>"+
          "update announcement_management set amTitle=#{amTitle}," +
          "amEplevel=#{amEplevel},amReleaseTime=#{amReleaseTime}," +
          "amState=#{amState},amIntroduction=#{amIntroduction}," +
          "amContentHeading=#{amContentHeading},amDetails=#{amDetails}" +

          " <if test='amPic!=\"\" and amPic!=null'>"+
          ",amPic=#{amPic}"+
          "</if>"+
          " where amid=#{amid}"+
          "</script>"
     )
     int edit(SysAnnounManagement sysAnnounManagement);

     /**
      *  删除大赛公告
      *  后台管理中的大事管理和校园工作台共同使用接口
      * @param amid
      * @return 结果
      */
     @Delete("delete from announcement_management where amid=#{amid}")
     int remove(int amid);

     /*
      * 查询大赛公告标题
      * */
     @Select("select distinct  amTitle from announcement_management")
     List<SysAnnounManagement> selectAmTitle();

     /*
      * 查询大赛公告状态
      * */
     @Select("select distinct (case  when amState='1' then'已发布'" +
          "  when amState='1' then'已发布'" +
          " when amState='2' then'已结束' end)'amState' " +
          " from announcement_management")
     List<SysAnnounManagement> selectAmState();


    /**
     * 查询公告信息
     * @return
     */
    @Select("select * from announcement_management where amState !=0   ORDER BY amReleaseTime DESC limit #{start},#{pageSize}")
    List<SysAnnounManagement> readAnnounMans(SysAnnounManagement sysAnnounManagement);

    /**
     * 查询公告信息条数
     * @return
     */
    @Select("select count(*) from  announcement_management where amState !=0")
    long readAnnounManTotal();


     @Select("select amid,amTitle,amIntroduction,DATE_FORMAT(amReleaseTime,'%Y年%m月%d') as amReleaseTime,amState,amDetails,amPic,amContentHeading,amEplevel,schoolName from announcement_management where amEplevel = #{amEplevel} and schoolName = #{schoolName} and amState != 0 order by amReleaseTime desc")
     List<SysAnnounManagement> selectManageByEpschoolAndEplevel(@Param("schoolName") String schoolName, @Param("amEplevel") String amEplevel);


     /**
      * 判断数据是否存在
      * */
     @Select("select count(1) from announcement_management where amTitle=#{amTitle} and amEplevel=#{amEplevel} and " +
          "amReleaseTime=#{amReleaseTime} and amState=#{amState} and amIntroduction=#{amIntroduction} and " +
          "amContentHeading=#{amContentHeading} and  amDetails=#{amDetails}")
     long exists(SysAnnounManagement sysAnnounManagement);
}
